﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace MDIDemo.Windows.Report
{
    public partial class frmBaoCaoDoanhSoTheoThoiGian : DevExpress.XtraEditors.XtraForm
    {
        Dictionary<string, object> _valueList = new Dictionary<string, object>();

        public Dictionary<string, object> ValueList
        {
            get { return _valueList; }
            set { _valueList = value; }
        }
        DataSet _ds = null;

        public DataSet DataSource { get { return _ds; } }
        string type = "BCDSBH";

        public string Type
        {
            get { return type; }
            set { type = value; }
        }

        public frmBaoCaoDoanhSoTheoThoiGian()
        {
            InitializeComponent();
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            Close();
        }
        public DataSet BuildDataSourceBPTDSBH()
        {
            DataSet _ds = null;
            string query = "";
            if (rgOption.SelectedIndex == 0)
            {
                //query = @"exec procNXHANG_getByMaHang @NGAYCT='{0:yyyy-MM-dd}',@LOAICT='{1}'";
                query = @"SELECT     NGAYCT, SUM(CHIETKHAU) as CHIETKHAU,SUM(TONGTIEN) as TONGTIEN,SUM( TIENMAT) as TIENMAT,SUM( CONGNO) as CONGNO, SUM(THUNGAY) as THUNGAY
                         FROM         GIAODICH WHERE NGAYCT='{0:yyyy-MM-dd}' and LOAICT='{1}'
                        GROUP BY NGAYCT";
                query = string.Format(query, dtpNgay.EditValue, "BH001");
            }
            else
            {
                query = @"SELECT     NGAYCT, SUM(CHIETKHAU) as CHIETKHAU,SUM(TONGTIEN) as TONGTIEN,SUM( TIENMAT) as TIENMAT,SUM( CONGNO) as CONGNO, SUM(THUNGAY) as THUNGAY
                         FROM         GIAODICH WHERE MONTH(NGAYCT)={0} and YEAR(NGAYCT)={1} and LOAICT='{2}'
                        GROUP BY NGAYCT";

                //query = @"exec procNXHANG_getByMaHangMonth @Month={0},@year={1},@LOAICT='{2}'";
                query = string.Format(query, Convert.ToDateTime(dtpNgay.EditValue).Month, Convert.ToDateTime(dtpNgay.EditValue).Year, "BH001");
            }
            BUS.CommonControl ctr = new BUS.CommonControl();
            _ds = ctr.executeSelectQueries(query);
            return _ds;
        }
        private void btnPrint_Click(object sender, EventArgs e)
        {
            _ds = BuildDataSourceBPTDSBH();

            if (_ds.Tables.Count == 0)
            {
                XtraMessageBox.Show("Dữ liệu không tồn tại!");
                return;
            }
            bool isdata = false;
            foreach (DataTable dt in _ds.Tables)
            {
                if (dt.Rows.Count > 0)
                {
                    isdata = true;
                    break;
                }
            }
            if (isdata == false)
            {
                XtraMessageBox.Show("Dữ liệu không tồn tại!");
                return;
            }
            Type = rgOption.EditValue.ToString();
            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }



        private void frmBangKeGTGT_Load(object sender, EventArgs e)
        {
            dtpNgay.EditValue = frmMain.__ngayMoSo;
            rgOption.SelectedIndex = 0;
        }
    }
}